package com.fg.pro.trade.controller;

import com.fg.pro.model.reponse.ResponseResult;
import com.fg.pro.model.trade.dto.SimulationDataDto;
import com.fg.pro.model.trade.dto.SimulationGoodsParamsDto;
import com.fg.pro.model.trade.dto.SimulationGoodsRequestParamsDto;
import com.fg.pro.model.trade.dto.SimulationStrDto;
import com.fg.pro.trade.service.TradeGoodsSimulationService;
import com.fg.pro.trade.utils.TradeGoodsSimulationUtils;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Tag(name = "tradeGoodsSimulation", description = "贸易数据商品模拟分析")
@RestController
@RequestMapping("tradeGoodsSimulation")
public class TradeGoodsSimulationController {

    @Autowired
    TradeGoodsSimulationUtils tradeGoodsSimulationUtils;

    @Autowired
    TradeGoodsSimulationService tradeGoodsSimulationService;

    @Operation(summary = "获取数据模拟规则", description = "")
    @GetMapping("/getRule")
    public ResponseResult getRule() {
//        List<SimulationStrDto> list = tradeGoodsSimulationUtils.getAllowCustomerLine().stream().map(item -> {
//                    SimulationStrDto simulationStrDto = new SimulationStrDto();
//                    simulationStrDto.setValue(item);
//                    return simulationStrDto;
//                })
//                .collect(Collectors.toList());
        List<String> list = tradeGoodsSimulationUtils.getAllowCustomerLine();
        return ResponseResult.okResult(list);
    }

    @Operation(summary = "添加数据模拟规则", description = "")
    @PutMapping("/saveRule")
    public ResponseResult saveRule(@RequestParam(required = true) String customerLine) {
        boolean save = tradeGoodsSimulationUtils.saveAllowCustomerLine(customerLine);
        return ResponseResult.okResult(save ? "添加成功" : "添加失败");
    }

    @Operation(summary = "添加全部数据模拟规则", description = "")
    @PutMapping("/saveAllRule")
    public ResponseResult saveAllRule(@RequestBody(required = true) List<String> customerLines) {
        boolean save = tradeGoodsSimulationUtils.saveAllAllowCustomerLine(customerLines);
        return ResponseResult.okResult(save ? "添加成功" : "添加失败");
    }

    @Operation(summary = "删除数据模拟规则", description = "")
    @DeleteMapping("/delRule")
    public ResponseResult del(@RequestParam(required = true) String customerLine) {
        boolean del = tradeGoodsSimulationUtils.delAllowCustomerLine(customerLine);
        return ResponseResult.okResult(del ? "删除成功" : "删除失败");
    }

    @Operation(summary = "贸易数据商品模拟分析（一级数据分类）", description = "参数为...")
    @PostMapping("/getCategoryFirByParams")
    public ResponseResult getCategoryFirByParams(
//            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
//            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date end,
//            @RequestParam(required = false) Long categoryFirId,
//            @RequestParam(required = false) Long categorySecId,
//            @RequestParam(required = false) Long saleType,
//            @RequestParam(required = false) Long customerId,
//            @RequestParam(required = false) Long goodsId,
//            @RequestParam(required = false) String customerLine,
//            @RequestParam(required = false) List<SimulationGoodsParamsDto> simulationGoodsList
            @RequestBody(required = true) SimulationGoodsRequestParamsDto simulationGoodsRequestParamsDto
    ) {
//        SimulationDataDto simulationDataDto = tradeGoodsSimulationService.getCategoryFirByParams(start,end,categoryFirId,categorySecId,saleType,customerId,goodsId,simulationGoodsList,customerLine);
        SimulationDataDto simulationDataDto = tradeGoodsSimulationService.getCategoryFirByParams(
                simulationGoodsRequestParamsDto.getStart(),
                simulationGoodsRequestParamsDto.getEnd(),
                simulationGoodsRequestParamsDto.getCategoryFirId(),
                simulationGoodsRequestParamsDto.getCategorySecId(),
                simulationGoodsRequestParamsDto.getSaleType(),
                simulationGoodsRequestParamsDto.getCustomerId(),
                simulationGoodsRequestParamsDto.getGoodsId(),
                simulationGoodsRequestParamsDto.getSimulationGoodsList(),
                simulationGoodsRequestParamsDto.getCustomerLine());
        return ResponseResult.okResult(simulationDataDto);
    }

    @Operation(summary = "贸易数据商品模拟分析（二级数据分类）", description = "参数为...")
    @PostMapping("/getCategorySecByParams")
    public ResponseResult getCategorySecByParams(
            @RequestBody(required = true) SimulationGoodsRequestParamsDto simulationGoodsRequestParamsDto) {
        SimulationDataDto simulationDataDto = tradeGoodsSimulationService.getCategorySecByParams(simulationGoodsRequestParamsDto.getStart(),
                simulationGoodsRequestParamsDto.getEnd(),
                simulationGoodsRequestParamsDto.getCategoryFirId(),
                simulationGoodsRequestParamsDto.getCategorySecId(),
                simulationGoodsRequestParamsDto.getSaleType(),
                simulationGoodsRequestParamsDto.getCustomerId(),
                simulationGoodsRequestParamsDto.getGoodsId(),
                simulationGoodsRequestParamsDto.getSimulationGoodsList(),
                simulationGoodsRequestParamsDto.getCustomerLine());
        return ResponseResult.okResult(simulationDataDto);
    }

    @Operation(summary = "贸易数据商品模拟分析（分类排序）", description = "参数为...")
    @PostMapping("/getCategoryListByParams")
    public ResponseResult getCategoryListByParams(
            @RequestBody(required = true) SimulationGoodsRequestParamsDto simulationGoodsRequestParamsDto) {
        SimulationDataDto simulationDataDto = tradeGoodsSimulationService.getCategoryListByParams(simulationGoodsRequestParamsDto.getStart(),
                simulationGoodsRequestParamsDto.getEnd(),
                simulationGoodsRequestParamsDto.getCategoryFirId(),
                simulationGoodsRequestParamsDto.getCategorySecId(),
                simulationGoodsRequestParamsDto.getSaleType(),
                simulationGoodsRequestParamsDto.getCustomerId(),
                simulationGoodsRequestParamsDto.getGoodsId(),
                simulationGoodsRequestParamsDto.getSimulationGoodsList(),
                simulationGoodsRequestParamsDto.getCustomerLine());
        return ResponseResult.okResult(simulationDataDto);
    }

    @Operation(summary = "贸易数据商品模拟分析（对内对外属性分组）", description = "参数为...")
    @PostMapping("/getCustomerDataBySaleType")
    public ResponseResult getCustomerDataBySaleType(
            @RequestBody(required = true) SimulationGoodsRequestParamsDto simulationGoodsRequestParamsDto) {
        SimulationDataDto simulationDataDto = tradeGoodsSimulationService.getCustomerDataBySaleType(simulationGoodsRequestParamsDto.getStart(),
                simulationGoodsRequestParamsDto.getEnd(),
                simulationGoodsRequestParamsDto.getCategoryFirId(),
                simulationGoodsRequestParamsDto.getCategorySecId(),
                simulationGoodsRequestParamsDto.getSaleType(),
                simulationGoodsRequestParamsDto.getCustomerId(),
                simulationGoodsRequestParamsDto.getGoodsId(),
                simulationGoodsRequestParamsDto.getSimulationGoodsList(),
                simulationGoodsRequestParamsDto.getCustomerLine());
        return ResponseResult.okResult(simulationDataDto);
    }


    @Operation(summary = "贸易数据商品模拟分析（客户路线分组）", description = "参数为...")
    @PostMapping("/getCustomerListByParams")
    public ResponseResult getCustomerListByParams(
            @RequestBody(required = true) SimulationGoodsRequestParamsDto simulationGoodsRequestParamsDto) {
        SimulationDataDto simulationDataDto = tradeGoodsSimulationService.getCustomerListByParams(simulationGoodsRequestParamsDto.getStart(),
                simulationGoodsRequestParamsDto.getEnd(),
                simulationGoodsRequestParamsDto.getCategoryFirId(),
                simulationGoodsRequestParamsDto.getCategorySecId(),
                simulationGoodsRequestParamsDto.getSaleType(),
                simulationGoodsRequestParamsDto.getCustomerId(),
                simulationGoodsRequestParamsDto.getGoodsId(),
                simulationGoodsRequestParamsDto.getSimulationGoodsList(),
                simulationGoodsRequestParamsDto.getCustomerLine());
        return ResponseResult.okResult(simulationDataDto);
    }

    @Operation(summary = "贸易数据商品模拟分析（商品分组）", description = "参数为...")
    @PostMapping("/getGoodsListByParams")
    public ResponseResult getGoodsListByParams(
            @RequestBody(required = true) SimulationGoodsRequestParamsDto simulationGoodsRequestParamsDto) {
        SimulationDataDto simulationDataDto = tradeGoodsSimulationService.getGoodsListByParams(simulationGoodsRequestParamsDto.getStart(),
                simulationGoodsRequestParamsDto.getEnd(),
                simulationGoodsRequestParamsDto.getCategoryFirId(),
                simulationGoodsRequestParamsDto.getCategorySecId(),
                simulationGoodsRequestParamsDto.getSaleType(),
                simulationGoodsRequestParamsDto.getCustomerId(),
                simulationGoodsRequestParamsDto.getGoodsId(),
                simulationGoodsRequestParamsDto.getSimulationGoodsList(),
                simulationGoodsRequestParamsDto.getCustomerLine());
        return ResponseResult.okResult(simulationDataDto);
    }

    @Operation(summary = "贸易数据商品模拟分析（订单详情）", description = "参数为...")
    @PostMapping("/getOrderDetailByParams")
    public ResponseResult getOrderDetailByParams(
            @RequestBody(required = true) SimulationGoodsRequestParamsDto simulationGoodsRequestParamsDto) {
        SimulationDataDto simulationDataDto = tradeGoodsSimulationService.getOrderDetailByParams(simulationGoodsRequestParamsDto.getStart(),
                simulationGoodsRequestParamsDto.getEnd(),
                simulationGoodsRequestParamsDto.getCategoryFirId(),
                simulationGoodsRequestParamsDto.getCategorySecId(),
                simulationGoodsRequestParamsDto.getSaleType(),
                simulationGoodsRequestParamsDto.getCustomerId(),
                simulationGoodsRequestParamsDto.getGoodsId(),
                simulationGoodsRequestParamsDto.getSimulationGoodsList(),
                simulationGoodsRequestParamsDto.getCustomerLine());
        return ResponseResult.okResult(simulationDataDto);
    }

    @Operation(summary = "贸易数据商品模拟分析（标题）", description = "参数为...")
    @PostMapping("/getTitileByParams")
    public ResponseResult getTitileByParams(
            @RequestBody(required = true) SimulationGoodsRequestParamsDto simulationGoodsRequestParamsDto) {
        SimulationDataDto simulationDataDto = tradeGoodsSimulationService.getTitileByParams(simulationGoodsRequestParamsDto.getStart(),
                simulationGoodsRequestParamsDto.getEnd(),
                simulationGoodsRequestParamsDto.getCategoryFirId(),
                simulationGoodsRequestParamsDto.getCategorySecId(),
                simulationGoodsRequestParamsDto.getSaleType(),
                simulationGoodsRequestParamsDto.getCustomerId(),
                simulationGoodsRequestParamsDto.getGoodsId(),
                simulationGoodsRequestParamsDto.getSimulationGoodsList(),
                simulationGoodsRequestParamsDto.getCustomerLine());
        return ResponseResult.okResult(simulationDataDto);
    }

}
